package main

import (
	"flag"
	"fmt"
	"os"
)

var (
	user string
	age int
	sex string
)

func init(){
	flag.StringVar(&user,"u","","your name")
	flag.IntVar(&age,"i",0,"your age")
	flag.StringVar(&sex,"s","男","your sex")
}

func main(){
	flag.Parse() // 解析
	fmt.Printf("go run main.go -u %s -i %v -s %v",user,age,sex)

	if !flag.Parsed(){  // 表示是否已经执行过 flag.Parse() 执行过返回true
		fmt.Fprintf(os.Stderr, `flag version :0.01
Usage: flag [-u user] [-i age] [-s sex]

Options:
`)
		flag.PrintDefaults()
	}

}
